//===============================================================================
//
// AgileAssemblyCollection
//
// PURPOSE: 
// 
//
// NOTES: 
// 
//
//===============================================================================
//

//===============================================================================

using System.Reflection;

namespace Agile.Common.Reflections
{
    /// <summary>
    /// Collection of System.Assembly items.
    /// </summary>
    public class AgileAssemblyCollection : AgileCollection
    {
        #region Preserved Region - Developer Hand Written Code

        /// <summary>
        /// Adds a collection of AgileAssemblys to the collection.
        /// </summary>
        /// <param name="assemblies">Collection of assemblies to add to this collection.</param>
        public void AddRange(AgileAssemblyCollection assemblies)
        {
            foreach (AgileAssembly assembly in assemblies)
                Add(assembly);
        }

        /// <summary>
        /// Adds an arrya of AgileAssemblys to the collection.
        /// </summary>
        /// <param name="assemblies">Array of assemblies to add to this collection.</param>
        public void AddRange(AgileAssembly[] assemblies)
        {
            foreach (AgileAssembly assembly in assemblies)
                Add(assembly);
        }

        /// <summary>
        /// Adds an arrya of AgileAssemblys to the collection.
        /// </summary>
        /// <param name="assemblies">Array of assemblies to add to this collection.</param>
        public void AddRange(Assembly[] assemblies)
        {
            foreach (Assembly assembly in assemblies)
                Add(AgileAssembly.Build(assembly));
        }

        /// <summary>
        /// Checks if the given Assembly is in the collection.
        /// </summary>
        /// <param name="assembly">assembly to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public virtual bool Contains(Assembly assembly)
        {
            ArgumentValidation.CheckForNullReference(assembly, "assembly");
            foreach (AgileAssembly item in List)
            {
                if (item.Assembly.Equals(assembly))
                    return true;
            }
            return false;
        }

        #endregion // Preserved Region - Developer Hand Written Code

        #region Constructors and Factories

        /// <summary>
        /// Constructor
        /// </summary>
        internal AgileAssemblyCollection()
        {
        }

        /// <summary>
        /// Instantiate a new AssemblyCollection
        /// </summary>
        public static AgileAssemblyCollection Build()
        {
            return new AgileAssemblyCollection();
        }

        #endregion

        #region Strongly Typed IList Implementations

        /// <summary>
        /// Returns the AgileAssembly that is at the given index in the collection.
        /// </summary>
        public AgileAssembly this[int index]
        {
            get { return InnerList[index] as AgileAssembly; }
        }

        /// <summary>
        /// Add a new Assembly to the collection
        /// </summary>
        /// <param name="assembly">assembly to add to the collection.</param>
        public void Add(AgileAssembly assembly)
        {
            if (Contains(assembly))
            {
                string message = string.Format("Tried adding a AgileAssembly to the collection but it is already in it.");
                throw new AgileCommonException(message);
            }
            List.Add(assembly);
        }

        /// <summary>
        /// Remove a AgileAssembly from the collection
        /// </summary>
        /// <param name="assembly">assembly to remove from the collection.</param>
        public void Remove(AgileAssembly assembly)
        {
            InnerList.Remove(assembly);
        }

        /// <summary>
        /// Checks if the given AgileAssembly is in the collection
        /// </summary>
        /// <param name="lookForAssembly">assembly to look for in the collection.</param>
        /// <returns>True if the item is in the collection.</returns>
        public bool Contains(AgileAssembly lookForAssembly)
        {
            return InnerList.Contains(lookForAssembly);
        }

        /// <summary>
        /// Searches for the specified AgileAssembly and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="assembly">assembly to get the index of from the collection.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AgileAssembly assembly)
        {
            return base.InnerList.IndexOf(assembly);
        }

        /// <summary>
        /// Searches for the specified AgileAssembly and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="assembly">assembly to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AgileAssembly assembly, int startIndex)
        {
            return base.InnerList.IndexOf(assembly, startIndex);
        }

        /// <summary>
        /// Searches for the specified AgileAssembly and returns the zero-based index
        /// of the first occurrence within the section of the
        /// collection that starts at the
        /// specified index and contains the specified number of elements.
        /// </summary>
        /// <param name="assembly">assembly to get the index of from the collection.</param>
        /// <param name="startIndex">The zero-based starting index of the search.</param>
        /// <param name="count">The number of elements in the section to search.</param>
        /// <returns>The index of the item in the collection.</returns>
        public int IndexOf(AgileAssembly assembly, int startIndex, int count)
        {
            return base.InnerList.IndexOf(assembly, startIndex, count);
        }

        /// <summary>
        /// Inserts the AgileAssembly into the collection at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which value should be inserted.</param>
        /// <param name="assembly">assembly to insert into the collection.</param>
        public void Insert(int index, AgileAssembly assembly)
        {
            base.InnerList.Insert(index, assembly);
        }

        /// <summary>
        /// Copies a range of elements from the collection of AgileAssembly's to a compatible
        /// one-dimensional System.Array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="assemblies">The one-dimensional System.Array that is the destination of the elements copied from the collection. The System.Array must have zero-based indexing.</param>
        /// <param name="index">The zero-based index at which copying begins.</param>
        public void CopyTo(AgileAssembly[] assemblies, int index)
        {
            List.CopyTo(assemblies, index);
        }

        #endregion
    }
}